package com.action.bullet
{
	import com.action.ActionBullet;
	import com.logic.battle.BattleLogic;
	import com.logic.battle.BattleServer;
	import com.stage.item.Player;
	import com.utils.time.TimerClock;
	
	import mx.core.Application;
	
	public class ActionBulletNormal extends ActionBullet
	{
		public function ActionBulletNormal(player:Player, data:Object)
		{
			super(player, data);
		}
		
		public override function start(dir:int=1, moveDir:int=0):void{
			_threadId = TimerClock.getInstance().addEnterFrame(enterFrame);
			_anima.gotoAndPlay(0);
		}
		
		protected override function enterFrame():void{
			_anima.enterFrame();
			_anima.x += _dir * _speed;
			_distance -= _speed;
			_anima.y += _upSpeed;
			
			// 碰撞检测
			BattleServer.bulletHitPlayer(this);
			
			if(_distance <= 0){
				end();
			}
		} 
		
		public override function end():void{
			// 注意：这里有时候会出错，bug
			
			if(Application.application.container.contains(_anima)){
				Application.application.container.removeChild(_anima);
			}
			TimerClock.getInstance().removeEnterFrame(_threadId);
			_threadId = 0;
			delete BattleLogic.bulletList[bulletId];
		}
	}
}